Correctly discover exe suffix through rustc
authorAlex Crichton <alex@alexcrichton.com>
Mon, 28 Jul 2014 17:32:14 +0000 (10:32 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 28 Jul 2014 17:33:02 +0000 (10:33 -0700)
There was a bug when this was written in rustc that prevented this, but it has
since been fixed.

src/cargo/ops/cargo_rustc/context.rs

index 8ccd14bc7f24936bab4e69f16d27008c84fc0869..f151783256b001c17214ab23dcfa2287e85c62fb 100644 (file)
@@ -77,6 +77,7 @@ impl<'a, 'b> Context<'a, 'b> {
                            .arg("-")
                            .arg("--crate-name").arg("-")
                            .arg("--crate-type").arg("dylib")
+                           .arg("--crate-type").arg("bin")
                            .arg("--print-file-name");
         let process = match target {
             Some(s) => process.arg("--target").arg(s),
@@ -85,14 +86,13 @@ impl<'a, 'b> Context<'a, 'b> {
         let output = try!(process.exec_with_output());
 
         let output = str::from_utf8(output.output.as_slice()).unwrap();
-        let dylib_parts: Vec<&str> = output.trim().split('-').collect();
+        let mut lines = output.lines();
+        let dylib_parts: Vec<&str> = lines.next().unwrap().trim()
+                                          .split('-').collect();
         assert!(dylib_parts.len() == 2,
                 "rustc --print-file-name output has changed");
-        let exe_suffix = match target {
-            None => os::consts::EXE_SUFFIX,
-            Some(s) if s.contains("win32") || s.contains("windows") => ".exe",
-            Some(_) => "",
-        };
+        let exe_suffix = lines.next().unwrap().trim()
+                              .split('-').skip(1).next().unwrap().to_string();
 
         Ok(((dylib_parts[0].to_string(), dylib_parts[1].to_string()),
             exe_suffix.to_string()))